package com.chen.wow.day04.AOP;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 
 * <p>Title:Audience</>
 * <p>Description:切面</p>
 * @author chen
 * 2017年4月21日下午2:08:19
 */
@Aspect
public class Audience {
	//切点@Pointcut
	@Pointcut("execution(** com.chen.wow.day04.AOP.Performance.perform(..))")
	public void performmance(){}
	
	@Before("performmance()")//前置通知
	public void slienceCellPhones(){
		System.out.println("Sliencing Cell Phones");
	}
	
	@AfterReturning("performmance()")//正常返回通知
	public void applause(){
		System.out.println("Good Good");
	}
	
	@AfterThrowing("performmance()")//抛出异常通知
	public void demandRefund(){
		System.out.println("Bad refund");
	}
	
	@Around("performmance()")//环绕通知
	public void watchPerformance(ProceedingJoinPoint jp){
		
		try {
			System.out.println("环绕通知 前1");
			jp.proceed();
			System.out.println("环绕通知 后1");
		} catch (Throwable e) {
			System.out.println("环绕通知 Bad refund");
			e.printStackTrace();
		}
	}
}
